@ECHO OFF
REM /****************************************************************
REM 
REM     DEH Release
REM
REM ****************************************************************/
set HEW_MAKE_PATH=C:\Program Files\Renesas\Hew_13UL

set path=%path%;%HEW_MAKE_PATH%

echo ###################################
echo Start make %1 ......

REM del /Q ..\%1\%1\Debug\*.*
REM del /Q ..\loader\loader_%1\Debug*.*
REM del /Q ..\vup\firm_update_%1\Debug\*.*
REM del /Q ..\11_media\media_module\Debug\*.*

if not exist %1 mkdir %1
if exist %1\*.mot del /Q %1\*.mot
if exist %1\*.map del /Q %1\*.map
if exist %1\*.bin del /Q %1\*.bin
if exist %1\*.log del /Q %1\*.log
if exist %1\checksum.txt del /Q %1\checksum.txt

hmake ..\%1\make\%1.mak PROJECT=ALL CONFIG=Debug >> %1\%1.log
if not errorlevel 0 goto error

rem copy mot file to release dirction
if not exist ..\%1\%1\Debug\%1.mot echo %1 make faild !!!
if not exist ..\%1\%1\Debug\%1.mot goto error
XCOPY /K /R /Y ..\%1\%1\Debug\%1.mot .\%1\ >> %1\%1.log
XCOPY /K /R /Y ..\%1\%1\Debug\%1.map .\%1\ >> %1\%1.log

if not exist ..\loader\loader_%1\Debug\loader.mot echo loader make faild !!!
if not exist ..\loader\loader_%1\Debug\loader.mot goto error
XCOPY /K /R /Y ..\loader\loader_%1\Debug\loader.mot .\%1\ >> %1\%1.log
XCOPY /K /R /Y ..\loader\loader_%1\Debug\loader.map .\%1\ >> %1\%1.log

if not exist ..\vup\firm_update_%1\Debug\firm_update.mot echo loader make faild !!!
if not exist ..\vup\firm_update_%1\Debug\firm_update.mot goto error
XCOPY /K /R /Y ..\vup\firm_update_%1\Debug\firm_update.mot .\%1\ >> %1\%1.log
XCOPY /K /R /Y ..\vup\firm_update_%1\Debug\firm_update.map .\%1\ >> %1\%1.log

rem mot file to bin file
mot2bin -o %1\loader.bin -s FFF80000 -m 10000 -i %1\loader.mot >> %1\%1.log
if not errorlevel 0 goto error
mot2bin -o %1\firm_update.bin -s 1C000100 -m 46500 -i %1\firm_update.mot >> %1\%1.log
if not errorlevel 0 goto error
mot2bin -o %1\%1_sys.bin -s 1C078500 -m A9B00 -i %1\%1.mot >> %1\%1.log
if not errorlevel 0 goto error
mot2bin -o %1\%1_media.bin -s 18100000 -m 100000 -i %1\%1.mot >> %1\%1.log
if not errorlevel 0 goto error

rem copy to output.bin
copy /B %1\loader.bin+%1\firm_update.bin+%1\%1_sys.bin+%1\%1_media.bin %1\output.bin >> %1\%1.log

rem get checksum
checksum -o %1\checksum.txt %1\output.bin >> %1\%1.log

rem bin to mot file
bin2mot -o %1\%2.mot -i %1\output.bin >> %1\%1.log
if not errorlevel 0 goto error

rem delete temp file
del .\%1\output.bin
del .\%1\loader.bin
del .\%1\firm_update.bin
del .\%1\%1_sys.bin
del .\%1\%1_media.bin

mot2bin -o %1\%1_sys.bin -s 1C078500 -m A9B00 -i %1\%1.mot -z >> %1\%1.log
if not errorlevel 0 goto error
mot2bin -o %1\%1_media.bin -s 18100000 -e 1C078500 -i %1\%1.mot -z >> %1\%1.log
if not errorlevel 0 goto error
copy /B %1\%1_sys.bin+%1\%1_media.bin %1\audio_temp.bin >> %1\%1.log

bin2mot -o %1\%1_temp.mot -i %1\audio_temp.bin >> %1\%1.log
if not errorlevel 0 goto error
mot2bin -o %1\audio.bin -i %1\%1_temp.mot -z -c >> %1\%1.log
if not errorlevel 0 goto error

copy /B ..\%1\usb_upgrade_header.txt+%1\audio.bin %1\%1.bin >> %1\%1.log

del .\%1\%1_sys.bin
del .\%1\%1_media.bin
del .\%1\audio_temp.bin
del .\%1\%1_temp.mot
del .\%1\audio.bin

echo make %1 ok !!!
goto end

:error
echo make %1 error!!!!!

:end

